package com.handpay.nocardpay.baselibrary.notification.view.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.handpay.nocardpay.baselibrary.R;
import com.handpay.nocardpay.baselibrary.commbase.view.fragment.BaseFragment;
import com.handpay.nocardpay.baselibrary.logutils.HPLog;
import com.handpay.nocardpay.baselibrary.notification.model.bean.NoticeBody;
import com.handpay.nocardpay.baselibrary.notification.service.NoticeService;
import com.handpay.nocardpay.baselibrary.utils.CommonUtils;
import com.handpay.nocardpay.baselibrary.widget.XRTextView;

/**
 * Created by fplei on 2017/8/10.
 * 通知详情
 */

public class NoticeDetailFragment extends BaseFragment {
    private TextView ndTitle,ndTime;
    private LinearLayout ndText;
    private Toolbar mToolbar;
    private NoticeBody notice=null;
    private String from=null;

    public static NoticeDetailFragment newInstance(Bundle mbundle) {
        Bundle args = mbundle;
        NoticeDetailFragment fragment = new NoticeDetailFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_notification_detail;
    }

    @Override
    public String getFragmentTitle() {
        return _mActivity.getString(R.string.mine_notice);
    }

    @Override
    public void initView(View view) {
        mToolbar = (Toolbar) view.findViewById(R.id.toolbar);
        Bundle bundle=this.getArguments();
        from=bundle.getString("from");
        notice=bundle.getParcelable("noticeBody");
        initToolbar(mToolbar, true, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(NoticeService.class.getSimpleName().equals(from)){
                    _mActivity.finish();
                }else{
                    pop();
                }
            }
        });
        ndTitle = (TextView)view.findViewById(R.id.notice_detail_title);
        ndTime = (TextView) view.findViewById(R.id.notice_detail_time);
        ndText = (LinearLayout)view.findViewById(R.id.notice_detail_text);
    }

    @Override
    public void initListener() {

    }

    @Override
    public void initData(Bundle savedInstanceState) {
        if (notice != null) {
            ndTitle.setText(getString(R.string.new_notice_detail_title_text) + notice.getTitle());
            ndTime.setText(CommonUtils.formatTime(notice.getTime()));
            XRTextView textview = new XRTextView(_mActivity, getResources().getDimension(R.dimen.normal_text_size), Color.rgb(71, 71, 71), CommonUtils.dp2px(20), CommonUtils.dp2px(20), 0, 0);
            String text = notice.getContent();
            textview.setText(CommonUtils.StringFilter(TextUtils.isEmpty(text) ? "" : text));
            ndText.addView(textview, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
            if (!notice.isRead()) {
                notice.setRead(true);
//                dataBaseModel.updateNotice(notice);
            }
        }
    }

}
